home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / c / MemPools.lha / free.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  2.6 KB  |  110 lines

  1. /**
  2. ***  MemPools:  malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright  (C)  1994    Jochen Wiedmann
  4. ***    changes       1998    Matthias Andree
  5. ***
  6. ***  This program is free software; you can redistribute it and/or modify
  7. ***  it under the terms of the GNU General Public License as published by
  8. ***  the Free Software Foundation; either version 2 of the License, or
  9. ***  (at your option) any later version.
  10. ***
  11. ***  This program is distributed in the hope that it will be useful,
  12. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ***  GNU General Public License for more details.
  15. ***
  16. ***  You should have received a copy of the GNU General Public License
  17. ***  along with this program; if not, write to the Free Software
  18. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ***
  20. ***
  21. ***  This file contains the malloc() replacement.
  22. ***
  23. ***
  24. ***  Computer:  Amiga 4000
  25. ***
  26. ***  Compilers: gcc 2.7.2
  27. ***             SAS/C 6.58
  28. ***
  29. ***
  30. ***  Author:    Jochen Wiedmann
  31. ***             Am Eisteich 9
  32. ***       72555 Metzingen
  33. ***             Germany
  34. ***
  35. ***             Phone: (0049) 7123 14881
  36. ***             Internet: jochen.wiedmann@uni-tuebingen.de
  37. ***
  38. ***  Bugfixes
  39. ***  Updates:   Matthias Andree
  40. ***             Stormstr. 14
  41. ***             58099 Hagen
  42. ***             Germany
  43. ***
  44. ***             Phone: +49-(0)23 31-96 30 72
  45. ***
  46. ***             E-Mail: mandree@dosis.uni-dortmund.de
  47. ***
  48. **/
  49.  
  50.  
  51.  
  52.  
  53. /*
  54.     Include files and compiler specific stuff
  55. */
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <exec/types.h>
  59. #if defined(__SASC)
  60. #include "my_alib_protos.h"
  61. #else
  62. #include <clib/alib_protos.h>
  63. #endif
  64. #include <proto/exec.h>
  65.  
  66. #include "mempools.h"
  67.  
  68.  
  69.  
  70. #ifdef DEBUG
  71. #define ADDSIZE (sizeof(memBlock)+sizeof(memBlockEnd))
  72. #else
  73. #define ADDSIZE (sizeof(memBlock))
  74. #endif
  75.  
  76.  
  77. void free(void *block)
  78.  
  79. {
  80.     memBlock *ptr;
  81.  
  82.     if ((ptr = block)) {
  83.     size_t size;
  84.  
  85.     ptr = ptr - 1;
  86.     size = ptr->size;
  87. #ifdef DEBUG
  88.     {
  89.         memBlockEnd *eptr;
  90.  
  91.         eptr = (memBlockEnd *) (((char *)(ptr+1))+size);
  92.  
  93.         if (ptr->realSize != size + ADDSIZE                         ||
  94.         memcmp(ptr->lowerBoundary, meatBeaf, sizeof(meatBeaf))  ||
  95.         memcmp(eptr->upperBoundary, meatBeaf, sizeof(meatBeaf))) {
  96.         extern void kprintf(const char *, ...);
  97.  
  98.         kprintf("Danger: Memory destroyed at %08lx.\n", ptr+1);
  99.         exit(0);
  100.         }
  101.  
  102.         memset(ptr->lowerBoundary, '\0', sizeof(meatBeaf));
  103.         memset(eptr->upperBoundary, '\0', sizeof(meatBeaf));
  104.     }
  105.     Remove((struct Node *) ptr);
  106. #endif
  107.     LibFreePooled(__MemPool, ptr, (ULONG)size + ADDSIZE);
  108.     }
  109. }
  110.